package com.ks.phone.wedget;

import android.content.Context;
import android.os.Environment;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;

import androidx.annotation.NonNull;

import com.ks.phone.R;
import com.ks.phone.databinding.DialogSettingBinding;
import com.ks.phone.manager.PreferenceManager;
import com.ks.phone.provider.ContextGlobal;

import razerdp.basepopup.BasePopupWindow;
import razerdp.util.animation.AnimationHelper;
import razerdp.util.animation.ScaleConfig;

public class PopupSetting extends BasePopupWindow {

    private DialogSettingBinding mBinding;

    public PopupSetting(Context context) {
        super(context);
        setContentView(R.layout.dialog_setting);
        setPopupGravity(Gravity.CENTER);
        setAutoMirrorEnable(true);      // 如果当前屏幕不足以完整显示您的PopupWindow，则PopupWindow会自行布置在其镜像位置。
        setBlurBackgroundEnable(false); // 设置PopupWindow弹出时是否模糊背景
//        setBackground(null);            // 设置无背景
        setOutSideDismiss(false);
        setBackPressEnable(false);
        setOutSideTouchable(false);
    }


    @Override
    public void onViewCreated(@NonNull View contentView) {
        mBinding = DialogSettingBinding.bind(contentView);
        mBinding.setPopup(this);
    }

    public String getContent() {
        return mBinding.et.getText().toString();
    }

    public void setOnConfirmClickListener(View.OnClickListener listener) {
        mBinding.tvConfirm.setOnClickListener(listener);
    }

    @Override
    public boolean onBeforeShow() {
        String recordPath = PreferenceManager.getInstance().getRecordPath(ContextGlobal.get().getContext());
        String replace = recordPath.replace(Environment.getExternalStorageDirectory()
                .getAbsolutePath(), "/内置SD卡");
        mBinding.et.setText(replace);
        return super.onBeforeShow();
    }

    @Override
    protected Animation onCreateShowAnimation() {
        return AnimationHelper.asAnimation()
                .withScale(ScaleConfig.CENTER)
                .toShow();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return AnimationHelper.asAnimation()
                .withScale(ScaleConfig.CENTER)
                .toDismiss();
    }
}
